# /etc/zsh/zshrc is sourced in interactive shells.  It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.

# Colors
test -f /etc/DIR_COLORS && eval `dircolors /etc/DIR_COLORS`

autoload -U colors
colors

# Default prompt
if [[ "$USER" == root ]]; then
    PROMPT="%{$bold_color$fg[red]%}%m %{$bold_color$fg[blue]%}%1~ %# %{$reset_color%}"
else
    PROMPT="%{$bold_color%}%n@%m %{$reset_color$fg[red]%}%1~ %# %{$reset_color%}"
fi

# Auto completion
autoload -U compinit
compinit

# An accept-line wrapper, see http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html
autoload -U accept-line
accept-line

# History
export HISTFILE=~/.zsh_history
export HISTSIZE=50000
export SAVEHIST=50000
export HISTCONTROL=ignoredups
setopt SHARE_HISTORY
setopt EXTENDED_HISTORY
setopt EXTENDED_GLOB

# Aliases
alias dir='ls --color=auto'
alias grep='grep --color=auto'
alias la='ls --color=auto -la'
alias ll='ls --color=auto -l'
alias ls='ls --color=auto'
alias mc='. /usr/share/mc/bin/mc-wrapper.sh'
alias rm='rm -i'
alias scp-resume='rsync --compress-level=3 --partial --progress --rsh=ssh'

# Key bindings
bindkey -e             # emacs key bindings
bindkey ' ' magic-space  # also do history expansion on space

bindkey "\e[3~" delete-char
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[H"  beginning-of-line
bindkey "\e[F"  end-of-line
bindkey "\e[7~" beginning-of-line
bindkey "\e[8~" end-of-line
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history

# Editor
export VISUAL="nano"

# Other options
setopt NO_BEEP
setopt CORRECT_ALL
setopt AUTO_LIST
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT
setopt INTERACTIVE_COMMENTS
setopt NONOMATCH
setopt NOPROMPT_SP

zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh_cache
zstyle ':acceptline:*' rehash true

case $TERM in
    xterm*)
        precmd () {print -Pn "\e]0;%n@%m: %~\a"}
        ;;
esac

if [ -f /etc/zsh/zsh_command_not_found ] && [ -x /usr/bin/command-not-found ]; then
  . /etc/zsh/zsh_command_not_found
fi
